//
// Created by Administrator on 2021/11/16.
// May Saint Diana bless you!
//
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>

using namespace std;

class Solution {
public:
    /**
     * dp
     * @param obstacles
     * @return
     */
    int minSideJumps(vector<int> &obstacles) {
        int n = (int) obstacles.size() - 1;
        vector<int> dp(3, INT_MAX);
        dp[1] = 0; // n 0 n
        for (int i = 0; i < n + 1; ++i) {
            if (obstacles[i] > 0) {
                dp[obstacles[i] - 1] = INT_MAX; // 障碍
            }
            int curMin = *min_element(dp.begin(), dp.end());
            for (int j = 1; j <= 3; ++j) {
                if (j == obstacles[i]) { // 障碍处
                    continue;
                } else {
                    if (dp[j - 1] != curMin)
                        dp[j - 1] = curMin + 1;
                }
            }
        }
        return *min_element(dp.begin(), dp.end());
    }
};

int main() {
    vector<int> obstacles{0, 1, 2, 3, 0};
    Solution solution;
    cout << solution.minSideJumps(obstacles) << endl;
    return 0;
}


